<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<title> 商品管理 </title>

<?php include VIEWS.'admin/style.html'?>

<script type="text/javascript">
<!--
function toggleClassNames() {
  var n = this.className;
  this.className = this.altClassName;
  this.altClassName = n;
}

function setupDatarows() {
  var v = document.getElementsByTagName("tr");
  for (var i = 0; i < v.length; i++) {
    if (v[i].className.indexOf("datarow") != -1) {
      v[i].onmouseover = toggleClassNames;
      v[i].onmouseout = toggleClassNames;
      v[i].altClassName = v[i].className + " hover";
    }
  }
}

window.onload = setupDatarows;

var aa = ajaxStart();
var i;

function toggleStat(iid) {
    i = iid;
    try {
        aa.call('/admin/itemsedit.php', 'ajaxAdminToggleStat', toggleStat_result, 'iid='+iid);
        return true;
    } catch (e) {
        alert('更改状态失败');
    }
}

function toggleStat_result(result) {
    var stat = result.result[0].data;
    if (stat==1) {
        $('stattext_'+i).innerHTML = ($('stattext_'+i).innerHTML=='下架' ? '<b>上架</b>' : '下架');
    } else {
        alert('更改状态失败');
    }
}
//-->
</script>

</head>

<body>

<?php include VIEWS.'admin/head.html'?>

<ul id="submenu">
    <li><a href='items.php' class="current">商品列表</a></li>
    <li><a href='itemsedit.php?add=1'>新增商品</a></li>
    <li><a href='itemscats.php'>商品分类</a></li>
    <li><a href='alert.php'>商品需求</a></li>
</ul>

<div id="body">

<div style="width:98%; margin-top:20px" align="center">

    <div style="float:left;padding-left:10px">
        <form method="get">
        <select name="pid">
        <option value="0">按分类查看</option>
        <?php foreach($cats['list'] as $v):?>
        <optgroup label="<?php echo $v['name']?>">
        <?php foreach($v['list'] as $vv):?>
        <option value="<?php echo $vv['id']?>"<?php if($pid==$vv['id']) echo ' selected';?>>- <?php echo $vv['name']?></option>
        <?php endforeach;?>
        </optgroup>
        <?php endforeach;?>
        </select>
        <input type="submit" value="GO" />
        </form>
    </div>
    <div style="float:right"><form method="get"><input type="hidden" name="sort" value="<?php echo $sort?>"><input type="text" name="s" value="<?php echo $search?>"> <input type="submit" value="查询">&nbsp;<a href="items.php?sort=<?php echo $sort?>"><small>清除搜索</small></a></form></div>

</div>

<br />
<br clear="all" />

<?php if (count($list['list'])==0):?><table style="border: 1px solid #aa0000;" width="100%" border="0" align="left" bgcolor="#FFE5E5" cellpadding="4" cellspacing="0"> <tr> <td> <div class="errorheader">没有找到任何相关商品。</div> </td> </tr> </table><br /><br clear="all">

<?php else:?>

<table class="reportV2" cellpadding="5" width="98%" cellspacing="0">
<tr class="columntitle"><td><a href="items.php?sort=id&s=<?php echo $data['search']?>">ID</a></td><td width="15%" nowrap=""><a href="items.php?sort=name&s=<?php echo $data['search']?>">名称</a></td><td nowrap=""><a href="items.php?sort=stuff&s=<?php echo $data['search']?>">材质</a></td><td nowrap=""><a href="items.php?sort=model&s=<?php echo $data['search']?>">型号</a></td><td nowrap=""><a href="items.php?sort=stocknum&s=<?php echo $data['search']?>">数量</a></td><td nowrap=""><a href="items.php?sort=pricein&s=<?php echo $data['search']?>">进价</a></td><td nowrap=""><a href="items.php?sort=price1&s=<?php echo $data['search']?>">零售价</a></td><td nowrap=""><a href="items.php?sort=price2&s=<?php echo $data['search']?>">原价</a></td><td nowrap=""><a href="items.php?sort=price3&s=<?php echo $data['search']?>">代销价</a></td><td nowrap=""><a href="items.php?sort=updated&s=<?php echo $data['search']?>">更新日期</a></td><td nowrap="">操作</td></tr>
<?php
foreach ($list['list'] as $v):
$itemsslist_i++;

if ($v['issale']==0) $hl = 'hl';
if ($v['issale']==2) $hl = 'hide';
?>
<tr class="<?php echo $hl ? $hl : ($itemsslist_i%2==0 ? 'even' : 'odd')?> datarow">
<td><b><a href="/<?php echo $v['id']?>" target="_blank"><?php echo $v['id']?></a></b></td>
<td nowrap="nowrap"><div id="i1<?php echo $v['id']?>"><?php echo $v['name']?></div></td>
<td class="px12"><div id="i2<?php echo $v['id']?>"><?php echo $v['stuff']?></div></td>
<td><div id="i3<?php echo $v['id']?>"><?php echo $v['model']?></div></td>
<td><div id="i4<?php echo $v['id']?>"><?php echo $v['stocknum']?></div></td>
<td><small>&yen;<?php echo $v['pricein']?></small></td>
<td><div id="i5<?php echo $v['id']?>" style="font-weight:bold"><?php echo $v['price1']?></div></td>
<td><small>&yen;<?php echo $v['price2']?></small></td>
<td><small>&yen;<?php echo $v['price3']?></small></td>
<td><small><?php echo date('y-m-d H:i', $v['updated'])?></small></td>
<td nowrap="">
<a href="itemsedit.php?id=<?php echo $v['id']?>">修改</a> -
<!--<a href="javascript:cRedirect('itemsedit.php?id=<?php echo $v['id']?>&p=<?php echo $list['page']['p']?>&remove=1&fromurl=<?php echo urlencode($_SERVER['REQUEST_URI'])?>', '确定要删除 “<?php echo $v['name']?>” 吗？')">删除</a> -->
<a id="stattext_<?php echo $v['id']?>" href="javascript:void(0);" onclick="javascript:toggleStat(<?php echo $v['id']?>)"><?php echo $v['issale'] ? '下架' : '<b>上架</b>'?></a> -
<a href="javascript:cRedirect('itemsedit.php?id=<?php echo $v['id']?>&amp;p=<?php echo $list['page']['p']?>&amp;copy=1&amp;fromurl=<?php echo urlencode($_SERVER['REQUEST_URI'])?>', '确定要复制 “<?php echo $v['name']?>” 吗？')">复制</a>
<script type="text/javascript">
    new Ajax.InPlaceEditor('i1<?php echo $v['id']?>','/admin/itemsedit.php',{cols:15,okButton:false,cancelText:'取消',callback: function(form, value) { return 'id=<?php echo $v['id']?>&inplace=1&name=' + encodeURIComponent(value)} });
    new Ajax.InPlaceEditor('i2<?php echo $v['id']?>','/admin/itemsedit.php',{cols:4,okButton:false,cancelText:'取消',callback: function(form, value) { return 'id=<?php echo $v['id']?>&inplace=1&stuff=' + encodeURIComponent(value)} });
    new Ajax.InPlaceEditor('i3<?php echo $v['id']?>','/admin/itemsedit.php',{cols:4,okButton:false,cancelText:'取消',callback: function(form, value) { return 'id=<?php echo $v['id']?>&inplace=1&model=' + encodeURIComponent(value)} });
    new Ajax.InPlaceEditor('i4<?php echo $v['id']?>','/admin/itemsedit.php',{cols:1,okButton:false,cancelText:'取消',callback: function(form, value) { return 'id=<?php echo $v['id']?>&inplace=1&stocknum=' + escape(value)} });
    new Ajax.InPlaceEditor('i5<?php echo $v['id']?>','/admin/itemsedit.php',{cols:2,okButton:false,cancelText:'取消',callback: function(form, value) { return 'id=<?php echo $v['id']?>&inplace=1&price1=' + escape(value)} });
</script>
</td></tr>
</tr>
<?php 
unset($hl);
endforeach;?>
</table>
<?php include VIEWS.'admin/pages.html'?>
<?php endif;?>

<?php include VIEWS.'admin/runtime.html'?>

</div>

<script type="text/javascript">
Element.addClassName('am3', 'current');
</script>

</body>
</html>
